import json
import os

# 定义文件夹列表
folder_list = [f"C{i}_Label" for i in range(1, 25)]  # 生成C1_Label到C24_Label

# 遍历每个文件夹
for folder_name in folder_list:
    print(f"正在处理文件夹: {folder_name}")
    
    # 检查文件夹是否存在
    if not os.path.exists(folder_name):
        print(f"警告: 文件夹 {folder_name} 不存在，跳过")
        continue
    
    # 遍历文件夹中的所有JSON文件
    json_files = [f for f in os.listdir(folder_name) if f.endswith('.json')]
    
    for json_file in json_files:
        json_path = os.path.join(folder_name, json_file)
        
        try:
            # 读取JSON文件
            with open(json_path, 'r', encoding='utf-8') as f:
                data = json.load(f)
            
            # 移除imageData字段
            if 'imageData' in data:
                del data['imageData']
                print(f"已移除 {json_file} 的imageData字段")
            else:
                print(f"{json_file} 中没有imageData字段")
            
            # 写回文件
            with open(json_path, 'w', encoding='utf-8') as f:
                json.dump(data, f, indent=2, ensure_ascii=False)
                
        except Exception as e:
            print(f"处理文件 {json_path} 时出错: {e}")

print("所有文件处理完成！")